package kaobei;

/**
 * @Created by pic
 * @Time 2019/9/2 0002
 * @Package cn.bdpro02.clonedemo
 * @Desc
 */
public class Lady implements Cloneable{
    private String name;
    private int age;
    private Cat cat;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //克隆lady对象
        Lady clone = (Lady)super.clone();
        /*深拷贝 克隆猫对象*/
        Cat clone1 = (Cat)this.getCat().clone();
        //将克隆的猫对象,设置到克隆的lady对象
        clone.setCat(clone1);
        return clone;
    }

    @Override
    public String toString() {
        return "Lady{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", cat=" + cat +
                '}';
    }

    public Lady() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Cat getCat() {
        return cat;
    }

    public void setCat(Cat cat) {
        this.cat = cat;
    }

    public Lady(String name, int age, Cat cat) {
        this.name = name;
        this.age = age;
        this.cat = cat;
    }
}
class Cat implements Cloneable{

    private String name;
    private int age;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public Cat() {
    }

    public Cat(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }


}
